// ViewList.cpp : implementation file
//

#include "stdafx.h"
#include "wfdeq.h"
#include "ViewList.h"

// CViewList

IMPLEMENT_DYNCREATE(CViewList, CListView)

CViewList::CViewList()
{

}

CViewList::~CViewList()
{
}

BEGIN_MESSAGE_MAP(CViewList, CListView)
	ON_WM_CONTEXTMENU()
	ON_WM_WINDOWPOSCHANGING()
	ON_WM_KEYDOWN()
END_MESSAGE_MAP()


// CViewList diagnostics

#ifdef _DEBUG
void CViewList::AssertValid() const
{
	CListView::AssertValid();
}

#ifndef _WIN32_WCE
void CViewList::Dump(CDumpContext& dc) const
{
	CListView::Dump(dc);
}
#endif
#endif //_DEBUG


// CViewList message handlers


BOOL CViewList::PreCreateWindow(CREATESTRUCT& cs) 
{
	cs.style |= LVS_REPORT;
	return CListView::PreCreateWindow(cs);
}

void CViewList::OnInitialUpdate() 
{
	CListView::OnInitialUpdate();

	CListCtrl& wndList = GetListCtrl ();

	wndList.SetExtendedStyle (LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);

	wndList.InsertColumn (0, _T("(x,y)"), LVCFMT_LEFT, 40);
	wndList.InsertColumn (1, _T("Analytical Sol."), LVCFMT_CENTER, 80);
	 //Insert items:
//	for (int i = 0; i < 100; i++)
//	{
//		const CString strItemFmt = _T("Item (%d, %d)");
//		
//		CString strItem;
//		strItem.Format (strItemFmt, 1, i + 1);
//		int iItem = wndList.InsertItem (i, strItem, 0);
//
//		for (int iColumn = 1; iColumn < 4; iColumn++)
//		{
//			strItem.Format (strItemFmt, iColumn + 1, i + 1);
//			wndList.SetItemText (iItem, iColumn, strItem);
//		}
//	}
	CString item;
		for (int i = 0; i < 5; i++)
	{
		for(int j=0;j<5;j++){
		item.Format(_T("(%d,%d)"),i,j);
		int iItem = wndList.InsertItem (i+j, item, 0);
		}
	}
}

void CViewList::OnContextMenu(CWnd* /*pWnd*/, CPoint point) 
{
	theApp.ShowPopupMenu (IDR_POPUP_EDIT, point, this);
}

void CViewList::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos) 
{
	CListView::OnWindowPosChanging(lpwndpos);
	
	// Hide horizontal scrollbar:
	ShowScrollBar (SB_HORZ, FALSE);
	ModifyStyle (WS_HSCROLL, 0, SWP_DRAWFRAME);
}

void CViewList::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	CListView::OnKeyDown(nChar, nRepCnt, nFlags);
	if (nChar == VK_LEFT || nChar == VK_RIGHT)
	{
		// Assume scroll left or right. Synchronize scorll bars:
		CMFCTabCtrl* pTabWnd = DYNAMIC_DOWNCAST (CMFCTabCtrl, GetParent ());
		ASSERT_VALID (pTabWnd);

		pTabWnd->SynchronizeScrollBar ();
	}
}

void CViewList::OnDraw(CDC* /*pDC*/)
{
	CListCtrl& wndList = GetListCtrl ();
	wndList.InsertColumn (2, _T("Solution"), LVCFMT_CENTER, 70);
	// Insert items:
	for (int i = 0; i < 100; i++)
	{
		const CString strItemFmt = _T("Item (%d, %d)");
		
		CString strItem;
		strItem.Format (strItemFmt, 1, i + 1);

		int iItem = wndList.InsertItem (i, strItem, 0);

		for (int iColumn = 1; iColumn < 4; iColumn++)
		{
			strItem.Format (strItemFmt, iColumn + 1, i + 1);
			wndList.SetItemText (iItem, iColumn, strItem);
		}
}
}

void CViewList::writreGrid(cfdGrid& grid,int n,CString name)
{
	CListCtrl& wndList = GetListCtrl ();
	wndList.InsertColumn (n, name, LVCFMT_CENTER, 70);
	// Insert items:
	CString item;
	CString strItem;
	for (int i = 0; i < 5; i++)
	{
		for(int j=0;j<5;j++){
		//	item.Format(_T("(%d,%d)"),i,j);
		//int iItem = wndList.InsertItem (i+j, item, 0);
		strItem.Format(_T("%lf"),grid.body[i][j]);
		wndList.SetItemText (5*i+j, n, strItem);
		}
	}
}